﻿@using PInitiatives.Models




@model PInitiatives.Models.User

@*Define new web grids*@
@{
    int numberOfActiveInitative = Model.getParticipatedInitiatives("participated").Where(i => i.State == "Active").Count();
    
    var createdInitatives = new WebGrid(
        source: Model.CreatedInitiatives,
        canPage: true, 
        canSort: true,
        rowsPerPage:3,
        defaultSort: "CreateDate",
        ajaxUpdateContainerId: "createdInitativesGrid"
        );

    var activeInitatives = new WebGrid(
        source: Model.getParticipatedInitiatives("participated").Where(i => i.State == "Active"),
        canPage: true,
        canSort: true,
        rowsPerPage: 3,
        defaultSort: "CreateDate",
        ajaxUpdateContainerId: "activeInitativesGrid"
        );
        
    var participatedInitiatives = new WebGrid(
        source: Model.getParticipatedInitiatives("participated").Where(i=> i.State != "Active"),
        canPage: true,
        canSort: true,
        rowsPerPage: 3,
        defaultSort: "CreateDate",
        ajaxUpdateContainerId: "participatedInitiativesGrid"
        );

    var reviews = new WebGrid(
        source: Model.UserReviews,
        canPage: true,
        canSort: true,
        rowsPerPage: 3,
        defaultSort: "CreateDate",
        ajaxUpdateContainerId: "reviewsGrid"
        );

    var createdReviews = new WebGrid(
        source: Model.CreatedReviews,
        canPage: true,
        canSort: true,
        rowsPerPage: 3,
        defaultSort: "CreateDate",
        ajaxUpdateContainerId: "createdReviewsGrid"
        );    

}

@{
    ViewBag.Title = Model.FirstName + " " + Model.LastName;
}



<div class="row-fluid show-grid">
<div class="span1 ini-icon-large"></div>
<div class="span8"><h3>@Model.FirstName @Model.LastName</h3></div>
<div class="span3"> Ocena: <h2>@Model.Rate</h2></div>
</div>

@if (ViewBag.MyAccount)
{
<div class="row-fluid">
<div class="span4" >

<i class=" icon-cog"></i>

    
    @Html.ActionLink("Ustawienia Konta", "AccountEdit", new { id = Model.ID }, new { @class = "button" })



</div></div>
    }

<div class="row-fluid show-grid">
<div class="span6">

@if (!ViewBag.MyAccount)
{
    <h4 class="ini-more-space">Oceny użytkownika</h4>
}
else
{ 
    <h4 class="ini-more-space">Twoje oceny</h4>
}
<br>
@if (Model.UserReviews.Count > 0)
{ 
    @reviews.GetHtml(
                tableStyle: "ini-table-black-align-center",
    htmlAttributes:
        new { id = "reviewsGrid" },
        columns: reviews.Columns(
             reviews.Column("AuthorRate", "Ocena", style: "author-rate"),
             reviews.Column("Initiatvie", "ivent", item => @Html.ActionLink((string)item.Initiative.Name, "Details", "Initiative", new { id = item.Initiative.ID }, new { title = item.Initiative.Description })),
             reviews.Column("RateType", "Typ oceny")
        //reviews.Column("InitiativeViewRate", "Ocena inicjatywy")
        //reviews.Column("Author.UserName", "Autor")
            )
    )
}
else
{
    if (!ViewBag.MyAccount)
    {
        <p>Ten użytkownik nie ma jeszcze żadnej oceny</p>
    }
    else
    { 
        <p>Nie posiadasz jeszcze żadnej oceny</p>
    }
}

</div>
<div class="span6">

@if (!ViewBag.MyAccount)
{
    <h4>Oceny wystawione przez użytkownika</h4>
}
else
{ 
    <h4>Oceny wystawione przez Ciebie</h4>
}

<br>
@if (Model.CreatedReviews.Count > 0)
{ 
    @createdReviews.GetHtml(
                    tableStyle: "ini-table-black-align-center",
    htmlAttributes:
            new { id = "createdReviews" },
            columns: createdReviews.Columns(
                createdReviews.Column("AuthorRate", "Ocena"),
                createdReviews.Column("Initiatvie", "ivent", item => @Html.ActionLink((string)item.Initiative.Name, "Details", "Initiative", new { id = item.Initiative.ID }, new { title = item.Initiative.Description })),
                createdReviews.Column("RateType", "Typ oceny")
        //createdReviews.Column("Author.UserName", "Autor")
        //createdReviews.Column("InitiativeViewRate", "Ocena inicjatywy")
            )
    )
}
else
{
    if (!ViewBag.MyAccount)
    {
        <p>Ten użytkownik nie ocenił jeszcze żadnego iventa</p>    
    }
    else
    { 
        <p>Nie oceniłeś jeszcze żadnego iventa</p>
    }

}

</div>
</div>

<div class="row-fluid show-grid">
<div class="span12">


@if (!ViewBag.MyAccount)
{
    <h4><i class="icon-star-empty"></i> Stworzone iventy:</h4>
}
else
{ 
    <h4><i class="icon-star-empty"></i> Twoje iventy:</h4>
}
<br>
@if (Model.CreatedInitiatives.Count > 0)
{
    
    @createdInitatives.GetHtml(
            tableStyle: "ini-table-black",
        htmlAttributes:
                    new { id = "createdInitativesGrid" },
                    columns: createdInitatives.Columns(
                        participatedInitiatives.Column("Name", "Nazwa", item => @Html.ActionLink((string)item.Name, "Details", "Initiative", new { id = item.ID }, new { title = item.Description })),
        //createdInitatives.Column("Description", "Opis"),
                        createdInitatives.Column("StartDate", "Data ropoczęcia"),
                        createdInitatives.Column("State", "Status"),
                        createdInitatives.Column("CreateDate", "Data utworzenia")
            )
        )
}
else
{
    if (!ViewBag.MyAccount)
    {
        <p>Użytkownik nie stworzył jeszcze żadnego iventa</p>
    }
    else
    { 
        <p>Nie stworzyłeś jeszcze żadnego iventa</p>
    }
}

</div>
</div>

<div class="row-fluid show-grid">
<div class="span12">

@if (!ViewBag.MyAccount)
{
    <h4><i class="icon-calendar"></i> Iventy w których bierze udział</h4>
}
else
{ 
    <h4><i class="icon-calendar"></i> Iventy w których bierzesz udział</h4>
}
<br>

@if (numberOfActiveInitative > 0)
{
    @activeInitatives.GetHtml(
        tableStyle: "ini-table-black",
        htmlAttributes:
                    new { id = "activeInitativesGrid" },
                    columns: createdInitatives.Columns(
                                participatedInitiatives.Column("Name", "Nazwa", item => @Html.ActionLink((string)item.Name, "Details", "Initiative", new { id = item.ID }, new { title = item.Description })),
        //activeInitatives.Column("Description", "Opis"),
                                activeInitatives.Column("StartDate", "Data rozpoczęcia"),
                                activeInitatives.Column("State", "Status"),
                                activeInitatives.Column("CreateDate", "Data utworzenia")
            )
        )
}
else
{
    if (!ViewBag.MyAccount)
    {
        <p>Użytkownik nie jest zapisany na żaden ivent</p>
    }
    else
    { 
        <p>Nie jesteś zapisany na żaden ivent</p>
    }
}

</div>
</div>


<div class="row-fluid show-grid">
<div class="span12">

@if (!ViewBag.MyAccount)
{
    <h4><i class="icon-check"></i> Iventy w których brał udział</h4>
}
else
{ 
    <h4><i class="icon-check"></i> Iventy w których brałeś udział</h4>
}
<br>
@if (Model.getParticipatedInitiatives().Count() > 0)
{

    if (Model.getParticipatedInitiatives().Where(i => i.State != "Active").Count() > 0)
    {
        @participatedInitiatives.GetHtml(
            tableStyle: "ini-table-black",
            htmlAttributes:
                        new { id = "participatedInitiativesGridGrid" },
                            columns: participatedInitiatives.Columns(
                                participatedInitiatives.Column("Name", "Nazwa", item => @Html.ActionLink((string)item.Name, "Details", "Initiative", new { id = item.ID }, new { title = item.Description })),
        //participatedInitiatives.Column("Description", "Opis"),
                                participatedInitiatives.Column("StartDate", "Data rozpoczęcia"),
                                participatedInitiatives.Column("State", "Status"),
                                participatedInitiatives.Column("CreateDate", "Data utworzenia")
                )
            )
    }
    else if (numberOfActiveInitative > 0)
    {
        if (!ViewBag.MyAccount)
        {
            <p>Użytkownik nie uczestniczył w żadnym ivencie, który został zakończony</p>
        }
        else
        { 
            <p>Nie uczestniczyłeś w żadnym ivencie, który został zakończony</p>
        }
    }

}
else
{
    if (!ViewBag.MyAccount)
    {
        <p>Użytkownik nie brał udziału w żadnych iventach</p>
    }
    else
    {
        <p>Nie brałeś udziału w żadnych iventach</p>
    }
}

</div>
</div>






